package com.xt.tea.utils;



import com.xt.tea.entity.enums.RequestResultEnum;
import com.xt.tea.entity.exception.GlobalException;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@Slf4j
public class ResponseUtil {

    public static void returnJson(HttpServletResponse response, String json){
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=utf-8");
        try (PrintWriter writer = response.getWriter()) {
            writer.print(json);
        } catch (IOException e) {
            log.error("response error", e);
        }
    }

    public static void returnRequestEnum(RequestResultEnum resultEnum){
        throw new GlobalException(resultEnum);
    }
}
